import {
    api_getSites
} from '../../api/api.transit.js'
export default{
    namespaced: true,
    state:{
        searchText:"",
        searchList:[]
    },
    mutations:{
        SET_SEARCH_LIST(state,data){
            state.searchList=data
        },
        SET_SEARCH_TEXT(state,data){
            state.searchText=data
        }
    },
    actions:{
        GET_SEARCH_LIST({rootState,state,commit}){
            return new Promise((resolve, reject)=>{
                const data = {
                    cityName:rootState.CityName,
					lineSiteName: state.searchText
                }
                api_getSites(data)
					.then((res) => {
						if(res.showapi_res_body.soulist){
                            let body=res.showapi_res_body.soulist
                            commit("SET_SEARCH_LIST",body)
                            resolve(body)
						}else{
                            commit("SET_SEARCH_LIST",[])
                            reject()
						}
					})
					.catch(() => {
                        commit("SET_SEARCH_LIST",[])
                        reject()
					})
            })
        },
        PASS_SITE({commit},site){
            commit('lineList/SET_SITE', site, {root: true}) 
        },
        PASS_LINE({commit},id){
            commit('lineDetails/SET_LINE_ID', id, {root: true}) 
        },
        
    }
}